﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Game
{
    namespace CommonAction
    {
        public interface IActionListener
        {
            void OnActivateAction(Action action);
            void OnDeactivateAction(Action action);
        }

        public class Action : List<IActionListener>
        {
            public void Activate()
            {
                foreach (IActionListener it in this)
                {
                    it.OnActivateAction(this);
                }
            }
            public void Deactivate()
            {
                foreach (IActionListener it in this)
                {
                    it.OnDeactivateAction(this);
                }
            }
        }

        public class ActionControl
        {
            private Action mAction;

            public ActionControl(Action action)
            {
                mAction = action;
            }

            public Action Action
            {
                get { return mAction; }
            }
        }

        public class ActionManager : Dictionary<String, Action>
        {
            Events.UserInputProvider mInputSubscriber = new Events.UserInputProvider();
            public Events.UserInputProvider InputSubscriber
            {
                get { return mInputSubscriber; }
                set { mInputSubscriber = value; }
            }
        }


        public class ActionDownControlKeyboard : CommonAction.ActionControl, Events.IUserInputListener
        {
            private Events.UserInput mInput;

            public ActionDownControlKeyboard(Events.UserInput input, CommonAction.Action action)
                : base(action)
            {
                mInput = input;
            }

            public void OnKeyDown(Events.UserInput input)
            {
                if (mInput.Compare(input))
                {
                    Action.Activate();
                }
            }

            public void OnKeyUp(Events.UserInput input)
            {
                //empty not using
            }

            public void OnMouseMove(Events.MouseUserInput input)
            {
            }

            public void OnMouseDown(Events.MouseUserInput input)
            {
            }

            public void OnMouseUp(Events.MouseUserInput input)
            {
            }
        }

        public class ActionUpControlKeyboard : CommonAction.ActionControl, Events.IUserInputListener
        {
            private Events.UserInput mInput;

            public ActionUpControlKeyboard(Events.UserInput input, CommonAction.Action action)
                : base(action)
            {
                mInput = input;
            }

            public void OnKeyDown(Events.UserInput input)
            {
                //empty not using
            }

            public void OnKeyUp(Events.UserInput input)
            {
                if (mInput.Compare(input))
                {
                    Action.Activate();
                }
            }

            public void OnMouseMove(Events.MouseUserInput input)
            {
            }

            public void OnMouseDown(Events.MouseUserInput input)
            {
            }

            public void OnMouseUp(Events.MouseUserInput input)
            {
            }
        }

        public class ActionUpDownControlKeyboard : CommonAction.ActionControl, Events.IUserInputListener
        {
            private Events.UserInput mInput;

            public ActionUpDownControlKeyboard(Events.UserInput input, CommonAction.Action action)
                : base(action)
            {
                mInput = input;
            }

            public void OnKeyDown(Events.UserInput input)
            {
                if (mInput.Compare(input))
                {
                    Action.Activate();
                }
            }

            public void OnKeyUp(Events.UserInput input)
            {
                if (mInput.Compare(input))
                {
                    Action.Deactivate();
                }
            }

            public void OnMouseMove(Events.MouseUserInput input)
            {
            }

            public void OnMouseDown(Events.MouseUserInput input)
            {
            }

            public void OnMouseUp(Events.MouseUserInput input)
            {
            }
        }
    }
}